package usage.trafficlight

class TrafficLightHandler {

    def green(TrafficLight trafficLight) {
        return trafficLight.colour == 'green'
    }

    def amber(TrafficLight trafficLight) {
        return trafficLight.colour == 'amber'
    }

    def redamber(TrafficLight trafficLight) {
        return trafficLight.colour == 'redamber'
    }

    def red(TrafficLight trafficLight) {
        return trafficLight.colour == 'red'
    }

    def change(Map args) {
        args.trafficLight.nextColour = args.to
    }

    def performChange(TrafficLight trafficLight) {
        trafficLight.colour = trafficLight.nextColour
    }

    def showColourOf(TrafficLight trafficLight) {
        println("${trafficLight.colour}")
        if(green(trafficLight)) {
            sleep(5000)
        } else if (red(trafficLight)){
            sleep(4000)
        } else if (amber(trafficLight)) {
            sleep(1000)
        } else if (redamber(trafficLight)) {
            sleep(500)
        }
    
    }
    
}